package com.aispeech.asr.apis.detection.config;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.buffer.NettyDataBufferFactory;

import com.alibaba.fastjson.JSON;

import io.netty.buffer.ByteBufAllocator;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Configuration
@ConfigurationProperties(prefix = "apis.detection")
@Data
@Slf4j
public class AppConfig {

    private String version;
    private boolean saveAudio;
    
    private String resRoot;
    private String aiopsHost;
    private Integer aiopsPort;
    
    private String cfgRelationship;
    private Map<String, String> cfgRelationshipMap = new HashMap<String,String>();
    

    @Bean
    public NettyDataBufferFactory nettyDataBufferFactory() {
        return new NettyDataBufferFactory(ByteBufAllocator.DEFAULT);
    }
    
    @PostConstruct
    public void init() {
        //initVadRelationshipMap();
        initVadRelationshipMap2();
    }
    
    public Map<String, String> getCfgRelationshipMap() {
        return cfgRelationshipMap;
    }
    
    private void initVadRelationshipMap2() {
    	try {
    		cfgRelationshipMap =  JSON.parseObject(cfgRelationship, Map.class);
    	}catch(Exception e){
    		log.error("vadRelationship is not json String");
    	}
    	
    }

}
